package net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class CommandThread extends Thread {
	private Socket socket;
	private CommandUnit command;
	private CommandHandleInterface handler;
	private ObjectInputStream in;
	private ObjectOutputStream out;
	
	CommandThread(Socket s){
		socket = s;
		handler = new CommandHandler();
		try {
			in = new ObjectInputStream(socket.getInputStream());
			out = new ObjectOutputStream(socket.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void run(){
		while(true){
			try {
					command = (CommandUnit) in.readObject();
//					System.out.println(command);
					handler.handle(command);
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	

}
